package com.qg.wcsopcuaqj.business.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qg.wcsopcuaqj.business.entity.TWcsTask;
import com.qg.wcsopcuaqj.business.mapper.TWcsTaskMapper;
import com.qg.wcsopcuaqj.business.params.TWcsTaksParam;
import com.qg.wcsopcuaqj.business.params.WcsTaskQueryParam;
import com.qg.wcsopcuaqj.business.service.ITWcsTaskService;
import com.qg.wcsopcuaqj.common.param.IdParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.qg.wcsopcuaqj.common.vo.R;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * wcs 任务信息表 前端控制器
 * </p>
 *
 * @author caixiang
 * @since 2021-11-10
 */
@RestController
@RequestMapping("/business/t-wcs-task")
public class TWcsTaskController {
    @Autowired
    ITWcsTaskService service;

    @Autowired
    TWcsTaskMapper mapper;

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "findAll")
    @ApiOperation(value="查询所有 wms传递给wcs的 任务", notes="查询所有 wms传递给wcs的 任务")
    private R<IPage<TWcsTask>> findAll(@RequestBody WcsTaskQueryParam wcsTaskQueryParam) {
        IPage<TWcsTask> all = mapper.findAll(new Page<TWcsTask>(wcsTaskQueryParam.getCurrent(), wcsTaskQueryParam.getSize()));
        return R.ok(all);
    }

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "create")
    @ApiOperation(value="用于wms 给 wcs 发任务用")
    private R<Integer> create(@RequestBody TWcsTaksParam tWcsTaksParam) {
        TWcsTask tWcsTask = new TWcsTask();
        BeanUtils.copyProperties(tWcsTaksParam, tWcsTask);
        int all = mapper.insertSelective(tWcsTask);
        return R.ok(all);
    }

    /**
     * 逻辑删除
     * */
    @PostMapping(value = "delete")
    @ApiOperation(value="逻辑删除这条任务，依据id")
    private R<Integer> delete(@RequestBody IdParam idParam) {
        TWcsTask tWcsTask = new TWcsTask();
        tWcsTask.setId(idParam.getId());
        tWcsTask.setValid(0);
        int all = mapper.updateById(tWcsTask,idParam.getId());
        if(all == 1){
            return R.ok(all).msg("成功");
        }else {
            return R.ok(all).msg("失败");
        }

    }

    /**
     * 逻辑删除
     * */
    @PostMapping(value = "findById")
    @ApiOperation(value="查找数据，依据id")
    private R<TWcsTask> findById(@RequestBody IdParam idParam) {
        return R.ok(mapper.findById(idParam.getId()));
    }
}